package com.fanqwz.kotlinmvvm.ui.activity

import android.databinding.ViewDataBinding
import android.os.Bundle
import com.fanqwz.kotlinmvvm.presenter.viewmodel.IModel
import com.fanqwz.kotlinmvvm.presenter.viewmodel.IViewModel
import com.fanqwz.kotlinmvvm.ui.compositor.ViewCompositor
import com.fanqwz.kotlinmvvm.view.IView
import com.fanqwz.kotlinmvvm.view.MVVM
import io.reactivex.subjects.BehaviorSubject
import javax.inject.Inject

/**
 * Created by fanqwz on 2017/10/31.
 */

abstract class MVVMActivity<V : IView, M : IModel, VM : IViewModel<M>> : ProgressActivity() {
    @Inject
    protected lateinit var mvvm: MVVM<V, M, VM>

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mvvm.init()
    }
    override fun buildViewCompositor(): ViewCompositor {
        super.buildViewCompositor().addChild(mvvm.view.viewCompositor)
        return mvvm.view.viewCompositor
    }

    override fun onStart() {
        super.onStart()
        mvvm.start()
    }

    override fun onStop() {
        super.onStop()
        mvvm.stop()
    }

    override fun onDestroy() {
        super.onDestroy()
        mvvm.destroy()
        refWatcher.watch(mvvm)
    }
}